/*
               File: PrcPresenca
        Description: Prc Presenca
             Author: GeneXus C# Generator version 10_2_5-78484
       Generated on: 6/6/2014 9:52:42.80
       Program type: Callable routine
          Main DBMS: sqlserver
*/
using System;
using System.Collections;
using GeneXus.Utils;
using GeneXus.Resources;
using GeneXus.Application;
using GeneXus.Metadata;
using System.Data;
using System.Data.SqlClient;
using GeneXus.Data;
using com.genexus;
using GeneXus.Data.ADO;
using GeneXus.Data.NTier;
using GeneXus.Data.NTier.ADO;
using System.Runtime.Remoting;
using GeneXus.WebControls;
using GeneXus.Http;
using GeneXus.Procedure;
using GeneXus.XML;
using GeneXus.Search;
using GeneXus.Encryption;
using GeneXus.Http.Client;
using System.Threading;
using System.Xml.Serialization;
using System.Data.SqlTypes;
using System.ServiceModel;
using System.Runtime.Serialization;
namespace GeneXus.Programs {
   public class prcpresenca : GXProcedure
   {
      public prcpresenca( )
      {
         context = new GxContext(  );
         DataStoreUtil.LoadDataStores( context);
         dsDefault = context.GetDataStore("Default");
         IsMain = true;
         context.SetDefaultTheme("GeneXusXEv2");
      }

      public prcpresenca( IGxContext context )
      {
         this.context = context;
         IsMain = false;
         dsDefault = context.GetDataStore("Default");
      }

      public void release( )
      {
      }

      public void execute( ref int aP0_ReuniaoId ,
                           ref long aP1_UserId ,
                           ref bool aP2_isPresente )
      {
         this.AV9ReuniaoId = aP0_ReuniaoId;
         this.AV8UserId = aP1_UserId;
         this.AV10isPresente = aP2_isPresente;
         initialize();
         executePrivate();
         aP0_ReuniaoId=this.AV9ReuniaoId;
         aP1_UserId=this.AV8UserId;
         aP2_isPresente=this.AV10isPresente;
      }

      public bool executeUdp( ref int aP0_ReuniaoId ,
                              ref long aP1_UserId )
      {
         this.AV9ReuniaoId = aP0_ReuniaoId;
         this.AV8UserId = aP1_UserId;
         this.AV10isPresente = aP2_isPresente;
         initialize();
         executePrivate();
         aP0_ReuniaoId=this.AV9ReuniaoId;
         aP1_UserId=this.AV8UserId;
         aP2_isPresente=this.AV10isPresente;
         return AV10isPresente ;
      }

      public void executeSubmit( ref int aP0_ReuniaoId ,
                                 ref long aP1_UserId ,
                                 ref bool aP2_isPresente )
      {
         prcpresenca objprcpresenca;
         objprcpresenca = new prcpresenca();
         objprcpresenca.AV9ReuniaoId = aP0_ReuniaoId;
         objprcpresenca.AV8UserId = aP1_UserId;
         objprcpresenca.AV10isPresente = aP2_isPresente;
         objprcpresenca.context.SetSubmitInitialConfig(context);
         objprcpresenca.initialize();
         ThreadPool.QueueUserWorkItem( new WaitCallback( executePrivateCatch ),objprcpresenca);
         aP0_ReuniaoId=this.AV9ReuniaoId;
         aP1_UserId=this.AV8UserId;
         aP2_isPresente=this.AV10isPresente;
      }

      void executePrivateCatch( object stateInfo )
      {
         try
         {
            ((prcpresenca)stateInfo).executePrivate();
         }
         catch ( Exception e )
         {
            GXUtil.SaveToEventLog( "Design", e);
            throw e ;
         }
      }

      void executePrivate( )
      {
         /* GeneXus formulas */
         /* Output device settings */
         if ( AV10isPresente )
         {
            AV13GXLvl2 = 0;
            /* Using cursor P00072 */
            pr_default.execute(0, new Object[] {AV8UserId, AV9ReuniaoId});
            while ( (pr_default.getStatus(0) != 101) )
            {
               A43UserId = P00072_A43UserId[0];
               A22ReuniaoId = P00072_A22ReuniaoId[0];
               AV13GXLvl2 = 1;
               /* Exiting from a For First loop. */
               if (true) break;
            }
            pr_default.close(0);
            if ( AV13GXLvl2 == 0 )
            {
               /*
                  INSERT RECORD ON TABLE TBLFrequencia

               */
               A22ReuniaoId = AV9ReuniaoId;
               A43UserId = AV8UserId;
               /* Using cursor P00073 */
               pr_default.execute(1, new Object[] {A43UserId, A22ReuniaoId});
               pr_default.close(1);
               dsDefault.SmartCacheProvider.SetUpdated("TBLFrequencia") ;
               if ( (pr_default.getStatus(1) == 1) )
               {
                  context.Gx_err = 1;
                  Gx_emsg = (String)(context.GetMessage( "GXM_noupdate", ""));
               }
               else
               {
                  context.Gx_err = 0;
                  Gx_emsg = "";
               }
               /* End Insert */
            }
         }
         else
         {
            /* Optimized DELETE. */
            /* Using cursor P00074 */
            pr_default.execute(2, new Object[] {AV8UserId, AV9ReuniaoId});
            pr_default.close(2);
            dsDefault.SmartCacheProvider.SetUpdated("TBLFrequencia") ;
            /* End optimized DELETE. */
         }
         this.cleanup();
      }

      public void cleanup( )
      {
         context.CommitDataStores("PrcPresenca");
         CloseOpenCursors();
         if ( IsMain )
         {
            context.CloseConnections() ;
         }
         exitApplication();
      }

      protected void CloseOpenCursors( )
      {
      }

      public override void initialize( )
      {
         scmdbuf = "";
         P00072_A43UserId = new long[1] ;
         P00072_A22ReuniaoId = new int[1] ;
         Gx_emsg = "";
         pr_default = new DataStoreProvider(context, new GeneXus.Programs.prcpresenca__default(),
            new Object[][] {
                new Object[] {
               P00072_A43UserId, P00072_A22ReuniaoId
               }
               , new Object[] {
               }
               , new Object[] {
               }
            }
         );
         /* GeneXus formulas. */
         context.Gx_err = 0;
      }

      private short AV13GXLvl2 ;
      private int AV9ReuniaoId ;
      private int A22ReuniaoId ;
      private int GX_INS7 ;
      private long AV8UserId ;
      private long A43UserId ;
      private String scmdbuf ;
      private String Gx_emsg ;
      private bool AV10isPresente ;
      private IGxDataStore dsDefault ;
      private int aP0_ReuniaoId ;
      private long aP1_UserId ;
      private bool aP2_isPresente ;
      private IDataStoreProvider pr_default ;
      private long[] P00072_A43UserId ;
      private int[] P00072_A22ReuniaoId ;
   }

   public class prcpresenca__default : DataStoreHelperBase, IDataStoreHelper
   {
      public ICursor[] getCursors( )
      {
         cursorDefinitions();
         return new Cursor[] {
          new ForEachCursor(def[0])
         ,new UpdateCursor(def[1])
         ,new UpdateCursor(def[2])
       };
    }

    private static CursorDef[] def;
    private void cursorDefinitions( )
    {
       if ( def == null )
       {
          Object[] prmP00072 ;
          prmP00072 = new Object[] {
          new Object[] {"@AV8UserId",SqlDbType.Decimal,15,0} ,
          new Object[] {"@AV9ReuniaoId",SqlDbType.Int,5,0}
          } ;
          Object[] prmP00073 ;
          prmP00073 = new Object[] {
          new Object[] {"@UserId",SqlDbType.Decimal,15,0} ,
          new Object[] {"@ReuniaoId",SqlDbType.Int,5,0}
          } ;
          Object[] prmP00074 ;
          prmP00074 = new Object[] {
          new Object[] {"@AV8UserId",SqlDbType.Decimal,15,0} ,
          new Object[] {"@AV9ReuniaoId",SqlDbType.Int,5,0}
          } ;
          def= new CursorDef[] {
              new CursorDef("P00072", "SELECT [UserId], [ReuniaoId] FROM [TBLFrequencia] WITH (NOLOCK) WHERE [UserId] = @AV8UserId and [ReuniaoId] = @AV9ReuniaoId ORDER BY [UserId], [ReuniaoId] ",false, GxErrorMask.GX_NOMASK | GxErrorMask.GX_MASKLOOPLOCK, false, this,prmP00072,1,0,false,true )
             ,new CursorDef("P00073", "INSERT INTO [TBLFrequencia] ([UserId], [ReuniaoId]) VALUES (@UserId, @ReuniaoId)", GxErrorMask.GX_NOMASK,prmP00073)
             ,new CursorDef("P00074", "DELETE FROM [TBLFrequencia]  WHERE [UserId] = @AV8UserId and [ReuniaoId] = @AV9ReuniaoId", GxErrorMask.GX_NOMASK | GxErrorMask.GX_MASKLOOPLOCK,prmP00074)
          };
       }
    }

    public void getResults( int cursor ,
                            IFieldGetter rslt ,
                            Object[] buf )
    {
       switch ( cursor )
       {
             case 0 :
                ((long[]) buf[0])[0] = rslt.getLong(1) ;
                ((int[]) buf[1])[0] = rslt.getInt(2) ;
                break;
       }
    }

    public void setParameters( int cursor ,
                               IFieldSetter stmt ,
                               Object[] parms )
    {
       switch ( cursor )
       {
             case 0 :
                stmt.SetParameter(1, (long)parms[0]);
                stmt.SetParameter(2, (int)parms[1]);
                break;
             case 1 :
                stmt.SetParameter(1, (long)parms[0]);
                stmt.SetParameter(2, (int)parms[1]);
                break;
             case 2 :
                stmt.SetParameter(1, (long)parms[0]);
                stmt.SetParameter(2, (int)parms[1]);
                break;
       }
    }

 }

}
